<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<!-- 先引入 jquery的 js -->
	<script type="text/javascript" src="easyui/js/jquery-1.8.0.min.js">
	</script>
	<!-- 引入 easyui的js -->
	<script type="text/javascript" src="easyui/js/jquery.easyui.min.js"></script>
	<!-- 引入国际化 js -->
	<script type="text/javascript" src="easyui/js/locale/easyui-lang-zh_CN.js"></script>
	<!-- 引入 默认样式 css -->
	<link rel="stylesheet" type="text/css" href="easyui/js/themes/default/easyui.css" />
	<!-- 引入 icon图标 css  -->
	<link rel="stylesheet" type="text/css" href="easyui/js/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="easyui/ztree/zTreeStyle.css" />
	<script type="text/javascript" src="easyui/ztree/jquery.ztree.all-3.5.js"></script>
	<script type="text/javascript" src="js/easyui-js.js"></script>
	<link rel="stylesheet" type="text/css" href="css/center.css" />
	<title>所有设备信息</title>
</head>

<body class="easyui-layout">
	<div id="searchWin" class="easyui-window" title="查找设品" data-options="iconCls:'icon-search',modal:true" closed="true" maximizable="false"
	 style="" collapsible="true" minimizable="true">

		<div region="center">
			<div class="easyui-panel" title="" style="width:400px"></div>

			<table cellpadding="5">
				<tr>
					<td>设备编码:</td>
					<td>
						<input id="sb_no" class="easyui-validatebox" type="text" name="sb_no" />
					</td>
				</tr>
				<tr>
					<td>设备名称：</td>
					<td>
						<input id="sb_name" class="easyui-validatebox" type="text" name="sb_name" />
					</td>
				</tr>
				<tr>
					<td>设备类型:</td>
					<td>
						<input id="sb_type" class="easyui-combobox" type="text" name="sb_type" value="-1" data-options="valueField:'id',textField:'name',url:'json/EquipmentType.json',required:true">
					</td>
				</tr> 
			</table>
			<input id="page" name="page" value="1" type="hidden" />
			<button href="#" class="easyui-linkbutton"  type="submit" id="search">查找设备</button>
			

		</div>

	</div>
	<div id="updateWin" class="easyui-window" title="修改设备信息" data-options="iconCls:'icon-save',modal:true" closed="true" maximizable="false"
	 style="" collapsible="true" minimizable="true">
		<form action="updatesbkcxx">
			<div region="center">
				<div class="easyui-panel" title="" style="width:400px"></div>

				<table cellpadding="3">
					<tr>
						<td>设备编码:</td>
						<td>
							<input id="sb_no" class="easyui-validatebox" type="text" name="sb_no" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<td>设备名称：</td>
						<td>
							<input id="sb_name" class="easyui-validatebox" type="text" name="sb_name"/>
						</td>
					</tr>
					<tr>
						<td>设备数量:</td>
						<td>
							<input id="sb_count" class="easyui-validatebox" type="text" name="sb_count" data-options="validType:'integer'" />
						</td>
					</tr>
					<tr>
						<td>设备类型:</td>
						<td>
							<input id="sb_type" class="easyui-combobox" type="text" name="sb_type" value="-1" data-options="valueField:'id',textField:'name',url:'json/EquipmentType.json',required:true">
						</td>
					</tr> 
					<tr>
						<td>设备容量：</td>
						<td>
							<input id="sb_volume" class="easyui-validatebox" type="text" name="sb_volume"/>
						</td>
					</tr>
					<tr>
						<td>备注：</td>
						<td>
							<input id="des" class="easyui-validatebox" type="text" name="des"/>
						</td>
					</tr>
				</table>
				<input id="page" name="page" value="1" type="hidden" />
				<button href="#" class="easyui-linkbutton"  type="submit" id="search">修改</button>
				

			</div>
		</form>

	</div>
	<div id="addWin" class="easyui-window" title="添加设备" data-options="iconCls:'icon-add',modal:true" closed="true" maximizable="false"
	style="" collapsible="true" minimizable="true">
	   <form action="addsbkcxx" id="addform" onsubmit="return check(this)">
		   <div region="center">
			   <div class="easyui-panel" title="" style="width:400px"></div>

			   <table cellpadding="5">
				    <tr>
					   <td>设备编码:</td>
					   <td>
						   <input id="sb_no" class="easyui-validatebox" type="text" name="sb_no" data-options="required:true" />
					   </td>
				   </tr>
				   <tr>
					   <td>设备名称：</td>
					   <td>
						   <input id="sb_name" class="easyui-validatebox" type="text" name="sb_name" data-options="required:true" />
					   </td>
				   </tr>
				   <tr>
					   <td>设备数量:</td>
					   <td>
						   <input id="sb_count" class="easyui-validatebox" type="text" name="sb_count" data-options="required:true" />
					   </td>
				   </tr>
				    <tr>
					   <td>设备类型:</td>
					   <td>
						   <input id="sb_type" class="easyui-combobox" type="text" name="sb_type" value="-1" data-options="valueField:'id',textField:'name',url:'json/EquipmentType.json',required:true">
					   </td>
				   </tr> 
				   <tr>
					<td>设备容量：</td>
					<td>
						<input id="sb_volume" class="easyui-validatebox" type="text" name="sb_volume"/>
					</td>
				</tr>
				<tr>
					<td>备注：</td>
					<td>
						<input id="des" class="easyui-validatebox" type="text" name="des"/>
					</td>
				</tr>
			   </table>
			   <input id="page" name="page" value="1" type="hidden" />
			   <button href="#" class="easyui-linkbutton"  type="submit" id="addEquipmentButton">增加</button>
				
				<!-- <button href="#" class="easyui-linkbutton"  type="submit" id="addEquipmentButton11">增加</button> -->

		   </div>
	   </form>

   </div>

	<div region="center" style="height:400px">
		<form action="delsbkcxx" method="get" id="delForm" style="height:400px">
			<table id="dg" class="easyui-datagrid"></table>
			<input name="ids" id="ids" type="hidden"/>
		</form>
	</div>



</body>
<script>
	function myformatter(date) {
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		var d = date.getDate();
		return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
	}

	function myparser(s) {
		if (!s) return new Date();
		var ss = (s.split('-'));
		var y = parseInt(ss[0], 10);
		var m = parseInt(ss[1], 10);
		var d = parseInt(ss[2], 10);
		if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
			return new Date(y, m - 1, d);
		} else {
			return new Date();
		}
	}
	function arrayToString(array,zd){
		var sum='';
		for(var i=0;i<array.length;++i){
			sum=sum+array[i][zd];
			if(i<array.length-1)
				sum=sum+',';
		}
		return sum;
	}

</script>
<script>
		var curr_time = new Date();
		//	$('#yXRQ1').datebox('setValue', myformatter(curr_time));	
		//	$('#yXRQ2').datebox('setValue', myformatter(curr_time));	

		function doSearch() {
			$('#dg').datagrid('load', {
				good: '11'
			});
		}
		function doDelete() {
			// 先判断 用户是否选择
			var array = $('#dg').datagrid('getSelections');
			if(array==null||array.length==0){
			  $.messager.alert('警告','请选择删除的列','info');
			  return;
			}
			
			var ids=arrayToString(array,'sb_no');
			if(confirm("确定删除？")){
			$('#ids').val(ids);
			$("#delForm").submit();
			}
		}
		var editrow = undefined;
		$('#dg').datagrid({
			fit: true,
			url: 'sbkcxx',
			pagePosition: "bottom",
			border: false,
			rownumbers: true,
			columns: [[
				 {
					field: 'ck',
					checkbox: true,
					width: 100
				}, 
				{
					field: 'sb_no',
					title: '设备编码',
					width: 100
				},
				{
					field: 'sb_name',
					title: '设备名称',
					width: 100,

				},
				{
					field: 'sb_count',
					title: '设备数量',
					width: 100,

				},
				{
					field: 'sb_type',
					title: '设备类型',
					width: 100,
					formatter: function (value, row, index) {
						var out;
						switch(value){
							case -1:out=''; break;
							case 0:out='玻璃品'; break;
							case 1:out='大型贵重设备';break;
							case 2:out='小型贵重设备';break;
							case 3: out='其他';break;						
						}
						return out;
					}


				},
				{
					field: 'sb_volume',
					title: '设备容量',
					width: 100,

				},
				{
					field: 'des',
					title: '备注',
					width: 100,

				}
			]],
			queryParams: {
				sb_no: $("#sb_no").val(),
				sb_name: $("#sb_name").val(),
				sb_type: $("#sb_type").val()
			},
			
			toolbar: [{
			iconCls: 'icon-add',
			handler: function () {
				$("#addWin").window('open')
			}
		},  {
			iconCls: 'icon-cancel',
			handler: function () {
				doDelete();
			}
		}, {
			iconCls: 'icon-search',
			handler: function () {
				$("#searchWin").window('open');
			}
		}],
			pageList: [5, 10],
			idField: "sb_no",
			pagination: true,
			onDblClickRow: function (rowIndex, rowData) {
				$("#updateWin").window('open');
				$('#updateWin #sb_no').val(rowData.sb_no)
				$('#updateWin #sb_name').val(rowData.sb_name)
				$('#updateWin #sb_count').val(rowData.sb_count)
				$('#updateWin #sb_type').combobox('setValue', rowData.sb_type);
				$('#updateWin #sb_volume').val(rowData.sb_volume)
				$('#updateWin #des').val(rowData.des)
			}
			
		});
</script>
<script type="text/javascript">
	$('#search').click(function () {
		$('#dg').datagrid('load', {
			sb_no: $("#sb_no").val(),
			sb_name: $("#sb_name").val(),
			sb_type: $("#sb_type").val()
		});
	})
	
	function check(){	
		 var sb_no= $("#addWin #sb_no").val();
		 var sb_name= $("#addWin #sb_name").val();
		 var sb_count= $("#addWin #sb_count").val();
		 if(sb_no==null||sb_no==""){
		 	alert("请输入设备编码");
		 	return false;
		 }else if(sb_name==null||sb_name==""){
		 	alert("请输入设备名称");
		 	return false;
		 }else if(sb_count==null||sb_count==""){
		 	alert("请输入设备数量");
		 	return false;
		 }
		 else{		
			$.ajax({
			type: "GET",
			url: "addsbkcxx",
			data: {"sb_no":sb_no},
			success: function (code) {
			if(code==-2){
				alert("添加失败，设备编码️已存在");
				window.location.href = "sbkcxx.html";
				return false;
			} else if(code!=-2){
				alert("添加成功");
				$('#addEquipmentButton').submit();
				window.location.href = "sbkcxx.html";
				return true;
			}
			 	}
			});
		} 
	}
	
</script>

</html>